import 'package:get/get.dart';
import 'package:share_fit/app/controllers/sports/components/goal_setting_dialog.dart';
import 'package:share_fit/app/controllers/sports/sports_const.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/log_utils.dart';
import 'package:share_fit/app/tools/unit_util.dart';
import 'package:share_fit/app/ute/uteped_const.dart';
import 'package:share_fit/app/ute/uteped_sports.dart';
import 'package:share_fit/app/controllers/home/exercise_records/model/exercise_type.dart';
import 'package:share_fit/generated/locales.g.dart';

import 'base_controller.dart';

abstract class BaseSportsController extends BaseController {
  UTEPedSports uTEPedSports = UTEPedSports.instance;

  /// 改变运动类型的选中状态
  changeSelectionsStatus(List<bool> selections, int index) {
    for (int i = 0; i < selections.length; i++) {
      selections[i] = false;
    }
    selections[index] = true;
  }

  void showGoalSettingWin(int sportType) {
    Get.dialog(
      GoalSettingDialog(sportType),
      barrierDismissible: false,
    );
  }

  /// 查询设备支持的运动类型列表，并保存至storage
  void queryWorkOutManageInfo() {
    dRemoteReqAsync(UTEPedConst.methodQueryWorkoutManageInfo, {}).then((value) {
      save(SportsConst.sportsManagementMap, value);
    });
  }

  List readSupportsSportsList() {
    return read(SportsConst.sportsManagementMap, defaultValue: []);
  }

  /// 根据分类获取对应的运动类型
  List<Type> getRealSupportSport(String classify) {
    return Type.getCodeListBy(classify, readSupportsSportsList());
  }

  getLengthUnitString() {
    return UnitUtil.getLengthUnit() == 0 ? LocaleKeys.length_unit_km.ts : LocaleKeys.length_unit_mi.ts;
  }

  void syncMySportListToDevice(List<ExerciseType> ets) {
    Map<String, Object> params = {UTEPedConst.typeList: ets.map((e) => e.type.code).toList()};
    dRemoteReqAsync(UTEPedConst.methodSetWorkoutManageInfo, params).then((value) => logger2.d('$value'));
  }
}
